package com.smarthospital.web.controller;

import com.github.pagehelper.PageInfo;
import com.smarthospital.common.Result.ResultDTO;
import com.smarthospital.entity.dto.DutiesDTO;
import com.smarthospital.entity.pojo.Doctor;
import com.smarthospital.service.DoctorService;
import com.smarthospital.service.OrderService;
import com.smarthospital.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * create by sym  2020/8/16 16:00.
 */
@RestController
@Slf4j
@RequestMapping("/doctor")
@Api(description = "医生接口")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @GetMapping("/list")
    @ApiOperation(value = "医生列表",
            notes =" 医生列表，根据医生等级分开，分页查询\n " +
                    "param: doctorLevel -> 医生级别 0_普通医生 1_专家" +
                    "       pageSize -> 页码大小\n" +
                    "       pageNum -> 当前页数" )
    public ResultDTO list(@RequestParam("doctorLevel")Integer doctorLevel,@RequestHeader("SH_TOKEN")String SH_TOKEN,
                           @RequestParam("pageSize")Integer pageSize, @RequestParam("pageNum")Integer pageNum) throws ParseException {
        log.info("list doctorLevel {}  pageSize {} pageNum {}",doctorLevel,pageSize,pageNum );
        PageInfo<Doctor> pageInfo = doctorService.querDoctors(doctorLevel,pageSize,pageNum);
        return ResultDTO.sucess(pageInfo);
    }

    @GetMapping("/getDoctorById")
    @ApiOperation(value = "医生详情",
            notes =" 医生详情，根据id查询\n " +
                    "param: doctorId -> 医生id"  )
    public ResultDTO getDoctorById(@RequestParam("doctorId")Integer doctorId,@RequestHeader("SH_TOKEN")String SH_TOKEN) throws ParseException {
        log.info("getDoctorById doctorId {}",doctorId);
        Doctor doctor = doctorService.getDoctorById(doctorId);
        return ResultDTO.sucess(doctor);
    }

    @GetMapping("/doctorDuty")
    @ApiOperation(value = "医生排班",
            notes =" 医生排班，从今天起后面的排班\n " +
                    "param: doctor -> 医生工号\n" )
    public ResultDTO doctorDuty(@RequestParam("doctor")String doctor,@RequestHeader("SH_TOKEN")String SH_TOKEN){
        log.info("doctorDuty doctor {}",doctor);
        List<DutiesDTO> list = doctorService.doctorDuty(doctor);
        return ResultDTO.sucess(list);
    }

    @GetMapping("/duties")
    @ApiOperation(value = "排班列表",
            notes =" 排班列表，从今天起后面7天的排班\n"+
                    "param: major -> 科室 不传则默认所有科室")
    public ResultDTO duties(@RequestParam(value = "major",required = false)String major,@RequestHeader("SH_TOKEN")String SH_TOKEN){
        List<DutiesDTO> list = doctorService.duties(major);
        return ResultDTO.sucess(list);
    }


}
